﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NGinnBPM.Lib.Schema
{
    /// <summary>
    /// Process definition validation message
    /// </summary>
    public class ValidationMessage
    {
        public bool IsError = false;
        public string Message;
        public NetNode Node;
        public Flow Flow;

        public ValidationMessage()
        {
        }
        public ValidationMessage(bool error, string msg, NetNode node)
        {
            Message = msg;
            IsError = error;
            Node = node;
        }

        public ValidationMessage(bool error, string msg, Flow fl)
        {
            Message = msg;
            IsError = error;
            Flow = fl;
        }

        public ValidationMessage(bool error, string msg)
        {
            Message = msg;
            IsError = error;
        }

        public override string ToString()
        {
            if (Flow != null)
            {
                return string.Format("Flow: {0}: {1}: {2}", Flow.ToString(), IsError ? "Error" : "Warning", Message);
            }
            else if (Node != null)
            {
                return string.Format("Node: {0}: {1}: {2}", Node.Id, IsError ? "Error" : "Warning", Message);
            }
            else
            {
                return string.Format("{0}: {1}", IsError ? "Error" : "Warning", Message);
            }
        }
    }
}
